package com.push_label.utils;

import java.io.IOException;
import java.util.Scanner;

public class FFmpegM3U8ToMP3 {

    public static void main(String[] args) {
//        System.out.println("请输入路径");
//        Scanner sc = new Scanner(System.in);
        String next = "E:\\迅雷下载\\IPZZ-293穿著竞赛泳衣的巨乳美女被恶质男人给侵犯-桃乃木香奈";

        String[] split = next.split("[\\\\]");
        String orginName = split[split.length - 1];
        String inputPath = next + "\\\\index.m3u8";
        String outPath = next + "\\\\"+orginName + ".mp4";

        System.out.println("inputPath = " + inputPath);
        System.out.println("outPath = " + outPath);
        String ffmpeg  = "ffmpeg -allowed_extensions ALL -i \"" +inputPath+
                "\" -c:v libx264 -c:a copy \"" +outPath+
                "\"";

        System.out.println(ffmpeg);

        try {
            // 使用 cmd /c 来执行多个命令
            String fullCommand = "cmd /c start \"FFmpeg转换\" /wait " +
                    "cmd /c \"" +ffmpeg+
                    " && timeout /t 5 /nobreak > nul\"";
            System.out.println("在新CMD窗口中执行: " + fullCommand);
            Process process = Runtime.getRuntime().exec(fullCommand);

            // 等待命令执行完成
            int exitCode = process.waitFor();
            System.out.println("CMD窗口已关闭，退出码: " + exitCode);

        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }


}
